<style lang="less" scoped>

  .el-row {
    margin-bottom: 20px;
  }

  .el-col {
    border-radius: 4px;
  }

  .bg-purple-dark {
    background: #ffffff;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

  .el-form-item {
    margin: 0px 20px 15px 20px;
  }

  .f-bs1 {
    border: 1px solid #dfe6ec;
  }

  .el-collapse {
    border: 0px;
    .el-collapse-item {
      border: 1px solid #dfe6ec;
      margin-bottom: 10px;
      .el-collapse-item__header {
        font-weight: bold;
        .el-collapse-item__header__arrow {
          display: none;
        }
      }
      .el-collapse-item__content {
        padding-bottom: 0px;
      }
      .el-collapse-item__wrap {
        border-bottom: 0px;
      }
    }
  }

  label {
    width: 100px;
  }

  .el-form-item[data-v-7da61f17] {
    margin: 0 0 0 0
  }

  .f-mt10 {
    margin-top: 10px;
  }

  .f-ml20 {
    margin-left: 20px;
  }

  .f-mr20 {
    margin-right: 20px;
  }

  .f-mb10 {
    margin-bottom: 10px;
  }

  .f-tar {
    text-align: right;
  }

  .f-h30 {
    height: 30px;
  }

  .f-c-red {
    color: red;
  }

  .el-radio-group {
    width: 60%;
  }

  .el-radio-invoice {
    margin-right: 30px;
  }

  .f-color {
    color: #25baaf;
  }

  .el-textarea {
    width: 86%;
  }

  .f-mb {
    margin-bottom: 0;
  }

  .f-fr {
    float: right;
  }

  .f-fl {
    float: left;
  }

  .f-lh38 {
    line-height: 38px;
  }

  .el-select {
    width: 100%;
  }

  .f-w233 {
    width: 100%;
  }

  .el-form-item__label {
    width: 150px;
  }

  .el-date-editor.el-input {
    width: 100%;
  }

  li {
    list-style-type: none;
  }

  .color-c8c8c8 {
    color: #c8c8c8;
  }

  .f-mt {
    margin-top: 0;
  }

</style>

<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="f-bs1 grid-content bg-purple-dark">
          <div class="f-fl f-lh38 f-ml20">
            订单编号：<label>{{orderForm.orderNumber}}&nbsp;&nbsp;</label><label>{{orderForm.orderSourceName}}&nbsp;&nbsp;</label><label>{{orderForm.orderStatusName}}</label>
          </div>
          <div class="f-fr f-lh38 f-mr20">
            <label>{{orderForm.mMebPersonal.partnerName}}&nbsp;&nbsp;</label><label>{{orderForm.organizationModel.name}}&nbsp;&nbsp;</label><label>{{orderForm.createDate}}&nbsp;&nbsp;</label>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-form ref="orderForm" label-position="right" label-width="110px" :model="orderForm" :rules="rules">
      <el-collapse v-model="activeNames">
        <el-collapse-item title="客户" name="1">
          <el-row class="f-mt10 f-mb10">
            <el-col :span="5">
              <el-form-item label="客户名称" prop="memberUserId">
                <el-select v-model="orderForm.memberUser"
                           remote
                           :remote-method="searchMemberUsers"
                           @change="searchMemberUsersChange"
                           filterable
                           placeholder="请选择客户">
                  <el-option v-for="mu in memberUsers" :label="mu.realName"
                             :key="mu.userId"
                             :value-key="mu.userId"
                             :value="mu">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="货运单号" prop="freightNumber">
                <el-input v-model="orderForm.freightNumber" placeholder="请输入货运单号"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="发货地址" name="3">
          <el-row>
            <el-col :span="5">
              <el-form-item label="发货人" prop="shipmentsContactName">
                <el-select v-model="orderForm.shipmentsContactName"
                           @visible-change="searchShipmentAddresses(109002002)"
                           filterable clearable placeholder="请选择发货人"
                           @change="shipmentsContactNameChange">
                  <el-option v-for="shipmentAddress in shipmentAddresses"
                             :label="shipmentAddress.contactName"
                             :key="shipmentAddress.id"
                             :value="shipmentAddress.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="手机号码" prop="shipmentsContactPhone">
                <el-input v-model="orderForm.shipmentsContactPhone" placeholder="请输入手机号码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="固定电话" prop="shipmentTelephone">
                <el-input v-model="orderForm.shipmentsTelephone" placeholder="请输入固定电话"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="所在地" prop="shipmentAddressesSelect">
                <address-select v-model="orderForm.shipmentAddressesSelect" :disabled="true"
                                @change="sendAddressSelectChange('shipmentAddress')"
                                placeholder="请选择地址"
                                class="f-w233"></address-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="街道" prop="shipmentsStreet">
                <el-input v-model="orderForm.shipmentsStreet" placeholder="请输入街道"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="" prop="add">
                <el-button v-if="orderForm.memberUserId !==''" @click="addContacts({type:109002002,name:'发货地址'})">
                  添加发货联系人
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="收货地址" name="4">
          <el-row>
            <el-col :span="5">
              <el-form-item label="收货人" prop="sendContactName">
                <el-select v-model="orderForm.sendContactName"
                           @visible-change="searchShipmentAddresses(109002001)"
                           filterable clearable placeholder="请选择收货人" @change="sendContactNameChange">
                  <el-option v-for="sendAddress in sendAddresses"
                             :label="sendAddress.contactName"
                             :key="sendAddress.id"
                             :value="sendAddress.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="手机号码" prop="sendContactPhone">
                <el-input v-model="orderForm.sendContactPhone" placeholder="请输入手机号码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="固定电话" prop="sendTelephone">
                <el-input v-model="orderForm.sendTelephone" placeholder="请输入固定电话"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="所在地" prop="sendAddressSelect">
                <address-select v-model="orderForm.sendAddressSelect" :disabled="true"
                                @change="sendAddressSelectChange('sendAddress')" placeholder="请选择地址"
                                class="f-w233"></address-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="街道" prop="sendStreet">
                <el-input v-model="orderForm.sendStreet" placeholder="请输入街道"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="" prop="add">
                <el-button v-if="orderForm.memberUserId !==''" @click="addContacts({type:109002001,name:'收货地址'})">
                  添加收货联系人
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="计划时间" name="2">
          <el-row style="margin-bottom: 0px">
            <el-col :span="5">
              <el-form-item class="f-mb" label="发货日期" prop="shipmentsDate">
                <div class="block f-h30" v-if="lineType !== 112006004">
                  <ue-el-date-picker v-model="orderForm.shipmentsDate"
                                     :picker-options="shipmentsDateValuePOS"></ue-el-date-picker>
                  <div style="float: left">
                    <label style="float: left;width: auto">提前发运享受优惠: </label><label class="f-c-red"
                                                                                    style="float: left;width: 30px"
                                                                                    v-html="discountText"></label>折
                  </div>
                </div>
                <div class="block f-h30" v-if="this.lineType===112006004">
                  <ue-el-date-picker v-model="orderForm.shipmentsDate"
                                     :picker-options="extractTimeValuePOS"></ue-el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="提货方式" prop="extractType">
                <el-select v-model="orderForm.extractType" @visible-change="searchextractTypes(105002)"
                           @change="searchextractTypeChange"
                           filterable placeholder="请选择提货方式">
                  <el-option v-for="et in extractTypes" :label="et.cnDictValname"
                             :key="et.dictVal"
                             :value="et.dictVal"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item class="f-mb" label="计划提货日期" prop="extractDate" v-if="orderForm.extractType===105002001"
                            :rules="[ {required: true,type:'date', message: '请选择计划提货日期', trigger: 'blur'}]">
                <div class="block f-h30">
                  <el-date-picker :disabled="orderForm.extractType === 105002002" format="yyyy-MM-dd"
                                  v-model="orderForm.extractDate" type="date" placeholder="选择计划提货日期"
                                  :picker-options="extractTimeValuePOS"></el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="计划提货时间" prop="extractTime" v-if="orderForm.extractType===105002001"
                            :rules="[ {required: true, message: '请选择计划提货时间', trigger: 'blur'}]">
                <el-select :disabled="orderForm.extractType === 105002002"
                           v-model="orderForm.extractTime"
                           filterable placeholder="请选择计划提货时间">
                  <el-option v-for="extractTime in extractTimes" :label="extractTime.cnDictValname"
                             :key="extractTime.dictVal"
                             :value="extractTime.dictVal"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5" :offset="5">
              <el-form-item label="送货方式" prop="sendType">
                <el-select v-model="orderForm.sendType" @visible-change="searchextractTypes(105001)"
                           filterable
                           @change="sendTypeTypeChange"
                           placeholder="请选择送货方式">
                  <el-option v-for="sendType in sendTypes" :label="sendType.cnDictValname"
                             :key="sendType.dictVal"
                             :value="sendType.dictVal"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item style="margin-bottom: 0px" label="计划送货时间" prop="sendTime"
                            v-if="orderForm.sendType===105001001">
                <div class="block f-h30">
                  <el-date-picker :disabled="orderForm.sendType === 105001002"
                                  v-model="orderForm.sendTime" type="date" placeholder="选择计划送货时间"
                                  :picker-options="sendTimeValuePOS"></el-date-picker>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-form ref="orderCargoForm" label-position="right" label-width="100px" :model="orderCargoForm"
                 :rules="orderCargoFormRules">
          <el-collapse v-model="activeNames">
            <el-collapse-item title="货物信息" name="5">
              <el-row>
                <el-col :span="5">
                  <el-form-item label="货物品名" prop="cargoId">
                    <el-select v-model="orderCargoForm.cargoModel"
                               filterable
                               clearable
                               placeholder="请选择货物品名" @change="cargoNameChange">
                      <el-option v-for="cargoModel in cargoNames" :label="cargoModel.name"
                                 :key="cargoModel.id"
                                 :value-key="cargoModel.id"
                                 :value="cargoModel"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="货物类型" prop="cargoTypeName">
                    <el-input :disabled="true" v-model="orderCargoForm.cargoTypeName"
                              placeholder="货物类型"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="货物包装" prop="packType">
                    <el-select v-model="orderCargoForm.packType"
                               @change="packTypeChanges"
                               @visible-change="searchPackTypes"
                               filterable placeholder="请选择货物包装">
                      <el-option v-for="packType in packTypes" :label="packType.cnDictValname" :key="packType.dictVal"
                                 :value="packType.dictVal"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="5">
                  <el-form-item label="重量（吨）" prop="weight">
                    <el-input type="number" step="0.01" v-model.number="orderCargoForm.weight"
                              @blur="calculatePrice"
                              placeholder="请输入重量"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="体积（方）" prop="volume">
                    <el-input type="number" step="0.01" v-model.number="orderCargoForm.volume"
                              @blur="calculatePrice"
                              placeholder="请输入体积"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="件数" prop="amount">
                    <el-input type="number" v-model.number="orderCargoForm.amount"
                              placeholder="请输入件数"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="10">
                  <el-form-item label="货物备注" prop="remark">
                    <el-input type="textarea" v-model="orderCargoForm.remark"
                              placeholder="请输入货物备注"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-collapse-item>
          </el-collapse>
        </el-form>

        <el-collapse-item title="服务" name="6">
          <el-row class="f-mb">
            <el-col :span="5">
              <label class="f-ml20">
                <el-popover
                  ref="popoverRetain"
                  placement="top-start"
                  width="200"
                  trigger="hover"
                  content="保价声明金额不低于3千，不高于100万保险费率0.02%">
                </el-popover>
                <label v-popover:popoverRetain>
                  <i class="f-color fa fa-info-circle" aria-hidden="true"></i>
                </label>
                保价运输
              </label>
            </el-col>
            <el-col :span="5">
              <label class="f-ml20">
                <el-popover
                  ref="popoverCollection"
                  placement="top-start"
                  width="200"
                  trigger="hover"
                  content="贷款金额大于0且不高于5万代收货款率0.3%">
                </el-popover>
                <label v-popover:popoverCollection><i class="f-color fa fa-info-circle"
                                                      aria-hidden="true"></i></label>
                代收货款
              </label>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="保价声明">
                <el-input type="number" step="0.01" @blur="addValueChange('bj')"
                          v-model.number="addValues[0].value"
                          placeholder="请输入保价声明"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="代收金额">
                <el-input type="number" step="0.01" @blur="addValueChange('ds')"
                          v-model.number="addValues[1].value"
                          placeholder="请输入代收金额"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="回单类型" prop="receiptType">
                <el-select :disabled="hdds" v-model="receiptType"
                           clearable
                           @change="searchReceiptTypeChange"
                           placeholder="请选择回单类型">
                  <el-option label="电子回单" value="101002003"></el-option>
                  <el-option label="原件回单" value="101002004"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mb">
            <el-col :span="5">
              <label class="f-ml20">
                <el-popover
                  ref="popoverInvoice"
                  placement="top-start"
                  width="200"
                  trigger="hover"
                  content="普通发票税率 3%">
                </el-popover>
                <label v-popover:popoverInvoice><i class="f-color fa fa-info-circle"
                                                   aria-hidden="true"></i></label>
                发 &nbsp; &nbsp; 票
              </label>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="发票类型" prop="invoiceType">
                <el-select :disabled="inds" v-model="invoiceTypeModel" clearable
                           @change="invoiceTypeChange"
                           placeholder="请选择发票类型">
                  <el-option label="个人普通发票" value="101002005"></el-option>
                  <el-option label="单位普通发票" value="101002006"></el-option>
                  <el-option label="增值税发票" value="101002007"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="发票抬头">
                <el-input v-if="orderForm.agingDictEntityId === 112006004" v-model="orderForm.valueMessage"
                          placeholder="请输入发票抬头"></el-input>
                <el-select v-if="orderForm.agingDictEntityId !== 112006004" v-model="taxsheetTitle"
                           remote
                           :remote-method="searchTaxsheetTitle"
                           @change="searchTaxsheetTitleChange"
                           filterable
                           placeholder="请选择发票抬头">
                  <el-option v-for="tht in taxsheetTitles" :label="tht.taxsheetTitle"
                             :key="tht.id"
                             :value="tht.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!--<el-row>-->
          <!--<el-radio-group v-model="orderForm.invoiceAddress" @change="invoiceAddressChange">-->
          <!--<el-form-item label="发票寄送地址">-->
          <!--<el-radio class="radio el-radio-invoice" label="shipmentsAccordance">与发货地址一致</el-radio>-->
          <!--<el-radio class="radio el-radio-invoice" label="sendAccordance">与收货地址一致</el-radio>-->
          <!--<el-radio class="radio el-radio-invoice" label="else">其他</el-radio>-->
          <!--</el-form-item>-->
          <!--</el-radio-group>-->
          <!--</el-row>-->
          <!--<el-row>-->
          <!--<el-col :span="5">-->
          <!--<el-form-item label="所在地">-->
          <!--<address-select v-model="invoiceAddressSelect" class="f-w233"-->
          <!--@change="invoiceAddressChange('else')"-->
          <!--:disabled="orderForm.invoiceAddress !=='else'"></address-select>-->
          <!--</el-form-item>-->
          <!--</el-col>-->
          <!--<el-col :span="5">-->
          <!--<el-form-item label="街道">-->
          <!--<el-input v-model="orderForm.invoiceAddressSelectStreet" placeholder="请输入街道"-->
          <!--:disabled="orderForm.invoiceAddress !=='else'"></el-input>-->
          <!--</el-form-item>-->
          <!--</el-col>-->
          <!--</el-row>-->
        </el-collapse-item>
        <el-collapse-item title="付款方式" name="7">
          <el-row>
            <el-radio-group v-model="orderForm.paymentType" @change="calculatePrice">
              <el-radio v-for="py in paymentTypes" class="radio" :label="py.paymentType" :key="py.paymentType">{{py.paymentTypeName}}
              </el-radio>
            </el-radio-group>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="运输产品" name="8" property="agingId">
          <el-row>
            <el-radio-group v-if="lineType !== 111002004" v-model="orderForm.agingModel" prop="agingId"
                            @change="calculatePrice">
              <div v-for="shipping in shippings" :key="shipping.ageingType" class="f-mt10">
                <el-radio class="radio" :label="shipping">
                  {{shipping.ageingTypeName}}
                  <label v-if="shipping.ageingType!==112006003&&shipping.ageingType!==112006004"
                         class="f-ml20">{{shipping.remark}}</label>
                  <label v-if="shipping.ageingType!==112006003&&shipping.ageingType!==112006004"
                         class="f-ml20 f-color">预计{{shipping.ageingScope}}到达，起步运费{{shipping.startToll}}，重货{{shipping.heavyStartToll}}元/吨（起），轻货{{shipping.gentlyStartToll}}元/方（起）
                  </label>
                  <label class="f-ml20" v-if="orderForm.agingModel.ageingType === 112006003">
                    <el-input type="number"
                              v-if="shipping.ageingType===112006003" v-model="freightPrice"
                              @change="pricing" style="margin-left: 20px;width: 125px"
                              placeholder="请输入价格"></el-input>
                    <el-input type="number"
                              v-if="shipping.ageingType===112006003" v-model="freightMsgPrice"
                              @change="pricing"
                              style="margin-left: 20px;width: 125px"
                              placeholder="请输入信息服务"></el-input>
                  </label>
                </el-radio>
              </div>
            </el-radio-group>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="订单备注" name="9">
          <el-row>
            <el-col :span="10">
              <el-form-item label="订单备注" prop="remark">
                <el-input type="textarea" v-model="orderForm.remark"
                          placeholder="请输入订单备注"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
      <div class="f-tar f-mt10 f-mb10">
        <div class="f-tar f-mt10 f-mb10">
          <el-button type="primary" style="width: auto;" @click="calculatePrice">预估费用</el-button>
        </div>
        <li class="f-mt10">订单金额：{{Math.round(orderForm.orderPrice * 100) / 100}} 元
          <label class="f-ml20 f-mt10">
            <el-popover ref="popoverInvoice" placement="right" width="400" trigger="click">
              <h2 class="f-ml20">费用详情</h2>
              <el-row class="f-mb">
                <el-col>
                  <p v-for="orderCostDetail in orderPrices" :key="orderCostDetail.costCode">
                    <label v-if="orderCostDetail.costCode === 101005002 && orderForm.agingDictEntityId !== 112006003">
                      <label style="width: 200px">{{orderCostDetail.costName}}</label>：
                      {{Math.round(linePrice * 100) / 100}}
                      (原价¥ {{Math.round((orderCostDetail.costPrice + orderPrice.preferentialLine + orderPrice.advanceOrder) * 100) / 100}}，提前下单优惠 {{orderPrice.advanceOrder}}元，线路优惠 {{orderPrice.preferentialLine}}元)
                    </label>
                    <label v-else-if="orderCostDetail.costCode === 101005005">
                      <label
                        style="width: 200px">{{orderCostDetail.costName}}</label>： {{Math.round(orderCostDetail.costPrice * 100) / 100}}(已保金额{{addValues[0].value}}元)
                    </label>
                    <label v-else-if="orderCostDetail.costCode === 101005006">
                      <label
                        style="width: 200px">{{orderCostDetail.costName}}</label>： {{Math.round(orderCostDetail.costPrice * 100) / 100}}(货代金额{{addValues[1].value}}元)
                    </label>
                    <label v-else>
                      <label
                        style="width: 200px">{{orderCostDetail.costName}}</label>： {{Math.round(orderCostDetail.costPrice * 100) / 100}}
                    </label>
                  </p>
                  <p class="color-c8c8c8 f-mb">温馨提示:</p>
                  <p class="color-c8c8c8 f-mb f-mt">以上费用仅供参考，普通客户准确报价以营业部电话咨询为准，月结客户以签订协议中的报价为准</p>
                  <p class="color-c8c8c8 f-mt">客服电话：400-796-8889</p>
                </el-col>
              </el-row>
            </el-popover>
            <label class="f-color" slot="reference" v-popover:popoverInvoice>
              费用详情》
            </label>
          </label>
        </li>
      </div>
      <div class="f-tar f-mt10 f-mb10">
        <el-button type="danger" style="width: auto;" @click="resetOrderForm('reset')">新增</el-button>
        <el-button type="primary" style="width: auto;" @click="createOrder(101001001,'save')">保存</el-button>
        <el-button type="primary" style="width: auto;" @click="createOrder(101001001,'saveAndReset')">保存&新增</el-button>
        <el-button type="primary" style="width: auto;" @click="createOrder(101001002,'saveAndReset')">保存&提交</el-button>
      </div>
    </el-form>

    <el-dialog :title="addressDialogTitle" size="tiny" :visible.sync="addressDialog">
      <el-form :model="myAddress" label-width="130px" ref="myAddress">
        <el-form-item label="地址类型" style="height: 55px">
          <el-input :disabled="true" v-model="myAddress.addressTypeName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="contactName" style="height: 55px">
          <el-input v-model="myAddress.contactName"
                    placeholder="请输入真实姓名"></el-input>
        </el-form-item>
        <el-form-item label="手机" prop="contactPhone" style="height: 55px"
                      :rules="[{min: 11,max:11, message: '长度请控制在11位', trigger: 'change'}]">
          <el-input type="number" v-model="myAddress.contactPhone"
                    placeholder="请输入手机号码"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="telephone" style="height: 55px"
                      :rules="[{min: 7,max:12, message: '长度请控制在7-12位', trigger: 'change'}]">
          <el-input type="number" v-model="myAddress.telephone"
                    placeholder="请输入固定电话"></el-input>
        </el-form-item>
        <el-form-item label="通信地址" prop="address" style="height: 55px">
          <address-select v-model="addressSelect"
                           placeholder="请选择地址"
                          class="f-w233"></address-select>
        </el-form-item>
        <el-form-item prop="street">
          <el-input auto-complete="off" v-model="myAddress.street" placeholder="街道-路-门牌号"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addressDialog = false">取消</el-button>
        <el-button type="primary" @click="addAddress">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getMemberUsers, searchDictEntitys, saveAddress } from '../../api/customer/maintain.js';
import { getStmParamByType } from '../../api/system/stmParam.js';
import { getFreightAddValue, searchReservationRuleFreights } from '../../api/freight/freightApi.js';
import { getDictEntityByDictCode, getDictEntity } from '../../api/system/Dict.js';
import { getItemNames } from '../../api/system/ItemName.js';
import { getAddresses } from '../../api/address/address.js';
import { saveOrder, searchLine, searchPrice } from '../../api/order/order.js';
import { searchInvoiceManageByFilters } from '../../api/meb-user/TaxsheetTitle.js';
import { isEmpty, getSelectObect } from '../../lib/util.js';
export default{
  data () {
    return {
      token: this.$store.state.token,
      radio: '',
      taxsheetTitles: [],
      taxsheetTitle: '',
      addressDialogTitle: '',
      addressDialog: false,
      addressSelect: [], // 每个页面用完要清空
      receiptType: '101002003',
      paymentTypes: [],
      lineType: '',
      freightContract: {},
      freightPrice: '',
      freightMsgPrice: '',
      memberUsers: [],
      extractTypes: [],
      sendTypes: [],
      shipmentAddresses: [],
      shipmentAddressesSelectModel: [], // 发货地址备用model
      sendAddressSelectModel: [], // 收货地址备用model
      shipmentAddressesSelectid: '', // 发货地址备用id
      sendAddressSelectId: '', // 收货地址备用id
      sendAddresses: [],
      invoiceAddressSelect: [],
      cargoNames: [],
      packTypes: [],
      invoiceTypes: [],
      receiptTypes: [],
      shippings: [],
      extractTimes: [{
        cnDictValname: '08:30-11:30',
        dictVal: '08:30-11:30'
      }, {
        cnDictValname: '13:30-18:00',
        dictVal: '13:30-18:00'
      }, {
        cnDictValname: '19:30-22:00',
        dictVal: '19:30-22:00'
      }],
      cnDictValname: '',
      send_contactPhone: '',
      send_telephone: '',
      send_street: '',
      shipment_contactPhone: '',
      shipment_telephone: '',
      shipment_street: '',
      cargoTypeName: '',
      shipmentsDateValuePOS: {
        discount: {},
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      extractTimeValuePOS: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      sendTimeValuePOS: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      shipmentsDateValue: '',
      extractTimeValue: '',
      activeNames: ['1', '2', '3', '4', '5', '6', '7', '8', '9'],
      orderCargoFormRules: {
        cargoId: [
          {required: true, message: '请输入货品名称', trigger: 'change'}
        ],
        amount: [
          {required: true, message: '请输入货品件数'},
          {type: 'integer', min: 1, max: 100000, message: '货品件数数量请控制在100000以内'}
        ],
        agingId: [
          {required: true, message: '请选择服务产品', trigger: 'blur'}
        ]
      },
      rules: {
        memberUserId: [
          {required: true, message: '请选择用户', trigger: 'blur'}
        ],
        shipmentsDate: [
          {type: 'date', required: true, message: '请输入发货日期', trigger: 'blur'}
        ],
        extractType: [
          {required: true, type: 'number', message: '请输入提货方式', trigger: 'change'}
        ],
        sendType: [
          {required: true, type: 'number', message: '请输入送货方式', trigger: 'change'}
        ],
        shipmentsContactName: [
          {required: true, message: '请输入发货人', trigger: 'blur'}
        ],
        shipmentAddress: [
          {required: true, message: '请输入发货人地址', trigger: 'blur'}
        ],
        shipmentAddressesSelect: [
          {required: true, type: 'array', message: '请输入发货人省市区', trigger: 'blur'}
        ],
        sendContactName: [
          {required: true, message: '请输入收货人', trigger: 'blur'}
        ],
        sendAddress: [
          {required: true, message: '请输入收货人地址', trigger: 'blur'}
        ],
        sendAddressSelect: [
          {required: true, type: 'array', message: '请输入收货人省市区', trigger: 'blur'}
        ]
      },
      orderCargoForm: {
        cargoTypeName: '',
        cargoModel: '',
        cargoName: '',
        cargoId: '',
        cargoType: '',
        packType: '',
        weight: '',
        volume: '',
        amount: '',
        remark: ''
      },
      receiptTypeModel: '', // 回单
      invoiceTypeModel: '', // 发票
      valueMessageqw: '', // 发票抬头
      addValues: [
        {
          dictValue: '101002001', // 保价声明
          value: '',
          remark: ''
        },
        {
          dictValue: '101002002', // 货代金额
          value: '',
          remark: ''
        },
        {
          dictValue: '', // 回单类型
          value: '',
          remark: ''
        },
        {
          dictValue: '', // 发票类型
          value: '',
          remark: '',
          taxsheetTitleId: ''
        }],
      orderForm: {
        valueMessage: '',
        orderNumber: '', // 订单编号
        orderSourceName: '', // 订单来源
        orderStatusName: '', // 订单状态名称
        createDate: '', // 录入时间
        receiptType: 101002003, // 录入时间
        mMebPersonal: {
          partnerName: ''
        },
        organizationModel: {
          name: ''
        },
        orderStatusModel: {
          cnDictValname: ''
        },
        agingDictEntityId: '', // 时效字典id
        preferentialLine: '', // 优惠线路
        advanceOrder: '', // 提前下单
        memberUserId: '',
        memberUserName: '',
        memberUser: '',
        freightNumber: '', // 货运单号
        shipmentsDate: '', // 发货时间
        extractType: '', // 提货方式
        extractDate: '',
        extractTime: '',
        sendType: '', // 送货类型
        orderPrice: '', // 订单总金额
        sendTime: '',
        shipmentsAddressId: '', // 发货地址
        shipmentAddressesSelect: [], // 发货地址数组
        shipmentsProvince: '', // 发货-省
        shipmentsProvinceId: '', // 发货-省id
        shipmentsCity: '', // 发货-市
        shipmentsCityId: '', // 发货-市id
        shipmentsCounty: '', // 发货-县
        shipmentsCountyId: '', // 发货-县id
        shipmentsContactName: '',
        shipmentsContactPhone: '',
        shipmentsTelephone: '',
        shipmentsAddress: '',
        shipmentsStreet: '',
        sendAddressSelect: [], // 收货地址数组
        sendAddressId: '', // 收货地址
        sendProvince: '', // 收货-省
        sendProvinceId: '', // 收货-省id
        sendCity: '', // 收货-市
        sendCityId: '', // 收货-市id
        sendCounty: '', // 收货-县
        sendCountyId: '', // 收货-县id
        sendContactName: '',
        sendContactPhone: '',
        sendTelephone: '',
        sendAddress: '',
        sendStreet: '',
        orderCargos: [], // 货物信息
        addValues: [], // 增值服务
        paymentType: '', // 付款方式
        orderStatus: '', // 订单状态
        agingModel: '', // 时效方式model
        agingId: '', // 时效方式
        agingName: '', // 时效方式名称
        orderCostDetails: [], // 订单费用明细
        invoiceAddressId: '', // 发票地址id
        invoiceAddress: '', // 发票地址id
        invoiceAddressProvince: '', // 发票省
        invoiceAddressProvinceId: '', // 发票省id
        invoiceAddressCity: '', // 发票市
        invoiceAddressCityId: '', // 发票市id
        invoiceAddressCounty: '', // 发票县
        invoiceAddressCountyId: '', // 发票县id
        invoiceAddressStreet: '', // 发票地址街道
        remark: ''
      },
      orderPrice: {
        grossfreight: '', // 总运费
        shortHaul: '', // 短途提货费
        trunkFreight: '', // 干线运费
        shortDeliveryCharge: '', // 短途送货费
        monthlyFee: '', // 月结费
        insured: '', // 保价
        collection: '', // 代收货款
        theReceipt: '', // 回单
        invoice: '', // 发票
        remark: '', // 备注
        costDetailTotal: ''// 费用明细的总和
      },
      orderPrices: [],
      sxType: '', // 时效方式
      inds: false, //
      hdds: false, //
      linePrice: '',
      discount: '',
      myAddress: {
        id: null,
        addressId: null,
        addressIds: null,
        userId: '',
        contactName: null,
        contactPhone: null,
        telephone: null,
        street: null,
        country: null,
        province: null,
        provinceId: null,
        city: null,
        cityId: null,
        options: [],
        collectAddress: '',
        county: null,
        countyId: null,
        postalCode: null,
        addressType: null,
        addressTypeName: null,
        isDefault: null
      },
      addresstype: [],
      addValueData: []
    };
  },
  methods: {
    addAddress () {
      let temp = '';
      this.myAddress.userId = this.orderForm.memberUserId;
      if (this.addressSelect != null) {
        this.myAddress.provinceId = this.addressSelect[0];
        this.myAddress.cityId = this.addressSelect[1];
        this.myAddress.countyId = this.addressSelect[2];
      }
      if (this.addressSelect[0] !== undefined) {
        temp += this.addressSelect[0] + ',';
      }
      if (this.addressSelect[1] !== undefined) {
        temp += this.addressSelect[1] + ',';
      }
      if (this.addressSelect[2] !== undefined) {
        temp += this.addressSelect[2];
      }
      this.myAddress.collectAddress = temp;
      this.$refs['myAddress'].validate((valid) => {
        if (valid) {
          saveAddress(this.myAddress).then((res) => {
            if (res.data.successFlg) {
              this.addressDialog = false;
              this.$message.success('添加成功！');
              this.searchShipmentAddresses(this.myAddress.addressType, res.data.obj.id);
            } else {
              this.$message.error(res.data.errorMsg);
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
        }
      });
    },
    addContacts (val) {
      this.addressSelect = [];
      if (this.$refs.myAddress) {
        this.$refs.myAddress.resetFields();
      }
      for (let p in this.myAddress) {
        if (this.myAddress[p] instanceof Array) {
          this.myAddress[p] = [];
        } else {
          this.myAddress[p] = null;
        }
      }
      this.addressDialogTitle = '添加联系人';
      this.addressDialog = true;
      this.myAddress.addressType = val.type;
      this.myAddress.addressTypeName = val.name;
    },
    addValueChange (val) {
      if (val === 'bj') {
        if (!isEmpty(this.addValues[0].value) && (this.addValues[0].value < 3000 || this.addValues[0].value > 1000000)) {
          return this.$message.error('保价金额范围在3000-1000000');
        }
      } else {
        if (!isEmpty(this.addValues[1].value) && (this.addValues[1].value < 1 || this.addValues[1].value > 50000)) {
          return this.$message.error('代收金额范围在1-50000');
        }
      }
      this.calculatePrice();
    },
    searchReservationRuleFreights () {
      searchReservationRuleFreights({
        token: this.token,
        filters: '',
        sorts: '',
        size: '30',
        page: '1'
      }).then((res) => {
        res.data.detailModelList.push({
          days: 0,
          percentage: ''
        });
        for (let days in res.data.detailModelList) {
          let mr = res.data.detailModelList[days];
          let push = mr.days + 1;
          var d = new Date(Date.now());
          d.setDate(d.getDate() + push - 1);
          var years = d.getFullYear();
          var months = d.getMonth();
          var day = d.getDate();
          this.shipmentsDateValuePOS.discount[new Date(years, months, day).getTime()] = '<label style="display: block;color: red;font-size: 9px;">' + mr.percentage + '</label>';
        }
      });
    },
    searchMemberUsersChange () {
      this.orderForm.memberUserId = this.orderForm.memberUser.userId;
      this.orderForm.sendContactName = null;
      this.orderForm.sendContactPhone = null;
      this.orderForm.sendTelephone = null;
      this.orderForm.sendStreet = null;
      this.orderForm.shipmentsContactName = null;
      this.orderForm.shipmentsContactPhone = null;
      this.orderForm.shipmentsTelephone = null;
      this.orderForm.shipmentsStreet = null;
      this.shipmentAddressesSelect = [];
      this.sendAddressSelect = [];
      this.searchTaxsheetTitle();
    },
    invoiceAddressChange (val) {
      let thisSendAddresses = this.orderForm.sendAddressSelect;
      let thisShipmentAddresses = this.orderForm.shipmentAddressesSelect;

      let inSendAddresses = this.shipmentAddressesSelectModel;
      let inShipmentAddresses = this.sendAddressSelectModel;

      if (val === 'else') {
        this.orderForm.invoiceAddressProvinceId = this.invoiceAddressSelect[0];
        this.orderForm.invoiceAddressCityId = this.invoiceAddressSelect[1];
        this.orderForm.invoiceAddressCountyId = this.invoiceAddressSelect[2];
      } else if (val === 'shipmentsAccordance') {
        if (thisSendAddresses[0] !== inSendAddresses[0] || thisSendAddresses[1] !== inSendAddresses[1] || thisSendAddresses[2] !== inSendAddresses[2]) {
          this.orderForm.invoiceAddressId = this.orderForm.shipmentsAddressId;
        } else {
          this.orderForm.invoiceAddressId = '';
        }

        this.orderForm.invoiceAddressProvinceId = this.orderForm.shipmentAddressesSelect[0];
        this.orderForm.invoiceAddressCityId = this.orderForm.shipmentAddressesSelect[1];
        this.orderForm.invoiceAddressCountyId = this.orderForm.shipmentAddressesSelect[2];
        this.orderForm.invoiceAddressStreet = this.orderForm.shipmentsStreet;
      } else {
        if (thisShipmentAddresses[0] !== inShipmentAddresses[0] || thisShipmentAddresses[1] !== inShipmentAddresses[1] || thisShipmentAddresses[2] !== inShipmentAddresses[2]) {
          this.orderForm.invoiceAddressId = this.orderForm.sendAddressId;
        } else {
          this.orderForm.invoiceAddressId = '';
        }

        this.orderForm.invoiceAddressProvinceId = this.orderForm.sendAddressSelect[0];
        this.orderForm.invoiceAddressCityId = this.orderForm.sendAddressSelect[1];
        this.orderForm.invoiceAddressCountyId = this.orderForm.sendAddressSelect[2];
        this.orderForm.invoiceAddressStreet = this.orderForm.sendStreet;
      }
    },
    searchReceiptTypeChange (val) {
      if (!isEmpty(val) && !isEmpty(val.dictVal)) {
        this.addValues[2].dictValue = val.dictVal;
        this.addValues[2].value = val.cnDictValname;
      }
      this.addValues[2].dictValue = val;
      let name = '';
      if (val === '101002004') {
        name = '原件回单';
      } else {
        name = '电子回单';
      }
      this.addValues[2].value = name;
      this.calculatePrice();
    },
    invoiceTypeChange (val) {
      let name = '';
      if (val === '101002005') {
        name = '个人普通发票';
      }
      if (val === '101002006') {
        name = '单位普通发票';
      }
      if (val === '101002007') {
        name = '增值税发票';
      }
      this.addValues[3].dictValue = val;
      this.addValues[3].value = name;
      this.calculatePrice();
    },
    searchextractTypeChange (val) {
      if (val === 105002002) {
        this.orderForm.extractDate = null;
        this.orderForm.extractTime = null;
      }
    },
    sendTypeTypeChange (val) {
      if (val === 105001002) {
        this.orderForm.sendTime = null;
      }
    },
    calculatePrice (val) {
      if (isEmpty(this.orderCargoForm.weight) && isEmpty(this.orderCargoForm.volume)) {
        return this.$message.error('体积和重量必须填写一项');
      }
      if (this.orderForm.agingDictEntityId === 112006004) {

      } else if (this.orderForm.agingModel.ageingType === 112006003) {
        this.paymentTypes = [{
          paymentType: 102002001,
          paymentTypeName: '现付'
        }, {
          paymentType: 102002002,
          paymentTypeName: '到付'
        }, {
          paymentType: 102002006,
          paymentTypeName: '回单结'
        }, {paymentType: 102002003, paymentTypeName: '月结30天'}, {
          paymentType: 102002004,
          paymentTypeName: '月结45天'
        }, {paymentType: 102002005, paymentTypeName: '月结90天'}
        ];
      } else if (this.orderForm.agingDictEntityId !== 112006004) {
        this.paymentTypes = [{
          paymentType: 102002001,
          paymentTypeName: '现付'
        }, {
          paymentType: 102002002,
          paymentTypeName: '到付'
        }, {
          paymentType: 102002006,
          paymentTypeName: '回单结'
        }];
      }
      if (this.orderForm.agingModel.ageingType === 112006003) {
        this.lineType = 112006003;
        this.orderForm.agingName = '定价快运';
        this.orderForm.agingDictEntityId = 112006003;
        this.pricing();
      } else {
        if (isEmpty(this.lineType)) {
          this.lineType = val.ageingType;
        }
        this.orderPrices = [];
        this.$refs['orderCargoForm'].validate((orderCargoFormValid) => {
          if (orderCargoFormValid) {
            if (isEmpty(this.orderForm.paymentType)) {
              return this.$message.error('请选择付款方式');
            }
            this.orderForm.agingId = this.orderForm.agingModel.id;
            this.orderForm.agingName = this.orderForm.agingModel.ageingTypeName;
            this.orderForm.agingDictEntityId = this.orderForm.agingModel.ageingType;
            if (isEmpty(this.orderForm.agingModel.ageingType)) {
              return this.$message.error('请选择运输产品方式');
            }
            let insuredV = '';
            let collectionV = '';
            let insuredProportion = '';
            let collectionProportion = '';
            let theReceiptV = '';
            getFreightAddValue(this.token).then((res) => {
              let AddValueData = res.data;
              if (AddValueData.successFlg) {
                for (let avd in AddValueData.detailModelList) {
                  let avdModel = AddValueData.detailModelList[avd];
                  if (avdModel.dictValue === 101002001) { // 保价比例
                    insuredV = this.addValues[0].value * avdModel.value;
                    insuredProportion = avdModel.value;
                  } else if (avdModel.dictValue === 101002002) { // 代收货款比例
                    collectionV = this.addValues[1].value * avdModel.value;
                    collectionProportion = avdModel.value;
                  } else if (avdModel.dictValue === 101002004) { // 回单比例
                    theReceiptV = avdModel.value;
                  }
                }
                let sp = this.shippings;
                for (let i = 0; i < sp.length; i++) {
                  if (sp[i].id === this.orderForm.agingId) {
                    this.sxType = sp[i].ageingType;
                  }
                }
                // 用于参与计费的model
                let priceModel = {
                  insuredProportion: insuredProportion, // 保价比例
                  cargoType: this.orderCargoForm.cargoType, // 货物类型
                  userId: this.orderForm.memberUserId, // 货物类型
                  collectionProportion: collectionProportion, // 代收货款比例
                  theReceiptProportion: theReceiptV, // 回单比例
                  insuredValue: this.addValues[0].value, // 保价
                  collectionValue: this.addValues[1].value, // 代收货款
                  insured: insuredV, // 保价*比例
                  collection: collectionV, // 代收货款*比例
                  extractType: this.orderForm.extractType, // 提货方式
                  sendType: this.orderForm.sendType, // 送货方式
                  theReceipt: theReceiptV, // 回单
                  theReceiptType: this.addValues[2].dictValue, // 回单类型1111111111111
                  invoiceType: isEmpty(this.invoiceTypeModel) ? '' : this.addValues[3].dictValue, // 发票类型222222222222222
                  typeOfShipping: this.sxType, // 运输方式
                  weight: this.orderCargoForm.weight, // 重量
                  volume: this.orderCargoForm.volume, // 体积
                  startOrderAddressId: this.orderForm.shipmentsAddressId,
                  endOrderAddressId: this.orderForm.sendAddressId,
                  isFrhtContract: this.lineType === 112006004 ? 111002001 : 111002002,
                  baseFreightId: this.orderForm.agingId, // 基础运价ID
                  percentage: this.discount, // 优惠比例
                  payWay: this.orderForm.paymentType// 付款方式
                };
                searchPrice({
                  json_model: priceModel
                }).then((res) => {
                  if (res.data.successFlg) {
                    this.orderPrice = res.data.obj;
                    this.orderPrices = this.orderForm.orderCostDetails = res.data.detailModelList;
                    getStmParamByType({
                      stmParamType: 'INSURED_MINIMUM_INSURED'
                    }).then((res) => {
                      let bjm = true;
                      for (let op in this.orderPrices) {
                        if (this.orderPrices[op].costCode === 101005005 && this.orderPrices[op].costPrice > 0) {
                          bjm = false;
                          if (this.orderPrices[op].costPrice < parseFloat(res.data.obj.stmParamVal)) {
                            this.orderPrices[op].costPrice = parseFloat(res.data.obj.stmParamVal);
                          }
                        }
                      }
                      if (bjm && !isEmpty(this.addValues[0].value)) {
                        this.orderPrices.push({
                          costCode: 101005005,
                          costName: '保价',
                          costPrice: parseFloat(res.data.obj.stmParamVal)
                        });
                      }
                    });
                    let totalPrice = 0;
                    for (let orderPrice in this.orderPrices) {
                      if (!isEmpty(this.orderPrices[orderPrice].costPrice) && this.orderPrices[orderPrice].costPrice !== 0) {
                        totalPrice += this.orderPrices[orderPrice].costPrice;
                      }
                      if (this.orderPrices[orderPrice].costCode === 101005002) {
                        this.linePrice = this.orderPrices[orderPrice].costPrice;
                      }
                    }
                    this.orderForm.orderPrice = totalPrice;
                    this.$message.success('费用计算成功');
                  } else {
                    this.orderForm.orderPrice = 0;
                  }
                });
              }
            });
          }
        });
      }
    },
    searchTaxsheetTitle (val) {
      let filters = '';
      if (isEmpty(val)) {
        filters = 'EQ_userId=' + this.orderForm.memberUserId;
      } else {
        filters = 'LIKE_taxsheetTitle=' + val + ';EQ_userId=' + this.orderForm.memberUserId;
      }
      searchInvoiceManageByFilters({
        filters: filters,
        sorts: '-createDate',
        size: '15',
        page: '1'
      }).then((res) => {
        this.taxsheetTitles = res.data.detailModelList;
      });
    },
    searchTaxsheetTitleChange (val) {
      this.addValues[3].taxsheetTitleId = val;
      this.orderForm.valueMessage = getSelectObect(val, 'id', this.taxsheetTitles).taxsheetTitle;
    },
    createOrder (orderStatus, type) {
      if (isEmpty(this.orderForm.orderPrice) || this.orderForm.orderPrice <= 0) {
        return this.$message.error('订单价格为零，无法提交');
      }
      if (isEmpty(this.orderCargoForm.weight) && isEmpty(this.orderCargoForm.volume)) {
        return this.$message.error('体积和重量必须填写一项');
      }
      let isyf = true;
      for (let op in this.orderPrices) {
        if (this.orderPrices[op].costCode === 101005002) {
          isyf = false;
          if (isEmpty(this.orderPrices[op].costPrice)) {
            return this.$message.error('请输入运费');
          }
        }
      }
      if (isyf) {
        return this.$message.error('请输入运费');
      }
      if (isEmpty(this.orderForm.paymentType)) {
        return this.$message.error('请选择付款方式');
      }
      if (isEmpty(this.orderForm.agingModel.id) && isEmpty(this.orderForm.agingDictEntityId)) {
        return this.$message.error('请选择运输产品');
      }
      let backupsAddValues = this.addValues;
      if (!isEmpty(this.addValues[0].value) && (this.addValues[0].value < 3000 || this.addValues[0].value > 1000000)) {
        return this.$message.error('保价金额范围在3000-1000000');
      }
      if (!isEmpty(this.addValues[1].value) && (this.addValues[1].value < 1 || this.addValues[1].value > 50000)) {
        return this.$message.error('代收金额范围在1-50000');
      }

      if (isEmpty(this.orderForm.orderPrice) && this.orderForm.orderCostDetails.length <= 0) {
        return this.$message.error('请先预估费用');
      }
      // 表单验证
      this.$refs['orderForm'].validate((valid) => {
        if (valid) {
          this.$refs['orderCargoForm'].validate((orderCargoFormValid) => {
            if (orderCargoFormValid) {
              this.orderForm.memberUserName = this.orderForm.memberUser.realName;
              this.orderForm.agingName = this.orderForm.agingModel.ageingTypeName;
              this.orderForm.orderStatus = orderStatus;
              this.orderForm.shipmentsProvinceId = this.orderForm.shipmentAddressesSelect[0];
              this.orderForm.shipmentsCityId = this.orderForm.shipmentAddressesSelect[1];
              this.orderForm.shipmentsCountyId = this.orderForm.shipmentAddressesSelect[2];
              this.orderForm.sendProvinceId = this.orderForm.sendAddressSelect[0];
              this.orderForm.sendCityId = this.orderForm.sendAddressSelect[1];
              this.orderForm.sendCountyId = this.orderForm.sendAddressSelect[2];

              if (this.orderForm.extractDate !== '' && this.orderForm.extractDate !== undefined && this.orderForm.extractDate != null) {
                this.orderForm.extractDate = new Date(this.orderForm.extractDate).Format('yyyy-MM-dd');
              }
              if (this.orderForm.sendTime !== '' && this.orderForm.sendTime !== undefined && this.orderForm.sendTime != null) {
                this.orderForm.sendTime = new Date(this.orderForm.sendTime).Format('yyyy-MM-dd');
              }
              this.orderForm.orderCostDetails = this.orderPrices;
              this.orderForm.orderCargos[0] = this.orderCargoForm;
              this.orderForm.addValues = this.addValues;
              let ishd = true;
              for (let oad in this.orderForm.addValues) {
                if (this.orderForm.addValues[oad].dictValue === 101002003 || this.orderForm.addValues[oad].dictValue === 101002004) {
                  ishd = false;
                }
              }
              if (ishd) {
                this.orderForm.addValues.push({dictValue: 101002003, value: '原件回单'});
              }
              this.orderForm.preferentialLine = this.orderPrice.preferentialLine;
              this.orderForm.advanceOrder = this.orderPrice.advanceOrder;
              // 移除空的
              saveOrder(this.token, this.orderForm).then((res) => {
                if (res.data.successFlg) {
                  if (type === 'saveAndReset' && res.data.successFlg) {
                    this.$message.success('保存成功');
                    setTimeout(() => {
                      this.resetOrderForm();
                    }, 1000);
                  }
                  this.$message.success('保存成功');
                  this.orderForm.orderNumber = res.data.obj.orderNumber;
                  this.orderForm.orderSourceName = res.data.obj.orderSourceName;
                  this.orderForm.orderStatusName = res.data.obj.orderStatusName;
                  this.orderForm.mMebPersonal.partnerName = res.data.obj.mMebPersonal.partnerName;
                  this.orderForm.organizationModel.name = res.data.obj.organizationName;
                  this.orderForm.createDate = res.data.obj.createDate;
                } else {
                  this.$message.error('保存失败');
                }

                this.addValues = backupsAddValues;
              });
            }
          });
        }
      });
    },
    searchMemberUsers (val) {
      let filters = isEmpty(val) ? 'logicStatus=111002002;status=111002001' : 'logicStatus=111002002;status=111002001;realName?' + val + ' g1';
      getMemberUsers({
        token: this.token,
        filters: filters,
        sorts: '+createDate',
        size: '15',
        page: '1'
      }).then((res) => {
        this.memberUsers = res.data.detailModelList;
      });
    },
    searchextractTypes (dictCodeId) {
      getDictEntityByDictCode({token: this.token, dictCode: dictCodeId}).then((res) => {
        if (dictCodeId === 105002) {
          this.extractTypes = res.data.detailModelList;
        } else {
          this.sendTypes = res.data.detailModelList;
        }
      });
    },
    searchShipmentAddresses (addressTypeId, addressId) {
      getAddresses({
        token: this.token,
        filters: 'addressType=' + addressTypeId + ' g0;userId=' + this.orderForm.memberUserId + ' g1',
        sorts: '',
        size: '15',
        page: '1'
      }).then((res) => {
        if (addressTypeId === 109002002) {
          this.shipmentAddresses = res.data.detailModelList;
          if (!isEmpty(addressId)) {
            for (let sa in this.shipmentAddresses) {
              if (this.shipmentAddresses[sa].id === addressId) {
                this.orderForm.shipmentsContactName = addressId;
                break;
              }
            }
          }
        } else {
          this.sendAddresses = res.data.detailModelList;
          if (!isEmpty(addressId)) {
            for (let sa in this.sendAddresses) {
              if (this.sendAddresses[sa].id === addressId) {
                this.orderForm.sendContactName = addressId;
                break;
              }
            }
          }
        }
      });
    },
    shipmentsContactNameChange (val) {
      let shipmentData = null;
      let shipmentAddresses = this.shipmentAddresses;
      for (let i = 0; i < shipmentAddresses.length; i++) {
        if (shipmentAddresses[i].id === val) {
          shipmentData = shipmentAddresses[i];
          this.orderForm.shipmentsAddressId = this.shipmentAddressesSelectid = shipmentData.id;
          this.orderForm.shipmentsContactName = shipmentData.contactName;
          this.orderForm.shipmentsContactPhone = shipmentData.contactPhone;
          this.orderForm.shipmentsTelephone = shipmentData.telephone;
          this.orderForm.shipmentsStreet = shipmentData.street;
          this.orderForm.shipmentAddressesSelect = [shipmentData.provinceId, shipmentData.cityId, shipmentData.countyId];
          this.shipmentAddressesSelectModel = [shipmentData.provinceId, shipmentData.cityId, shipmentData.countyId];
        }
      }

      this.sendAddressSelectChange();
    },
    sendContactNameChange (val) {
      let sendData = null;
      let sendAddresses = this.sendAddresses;
      for (let i = 0; i < sendAddresses.length; i++) {
        if (sendAddresses[i].id === val) {
          sendData = sendAddresses[i];
          this.orderForm.sendAddressId = this.sendAddressSelectId = sendData.id;
          this.orderForm.sendContactName = sendData.contactName;
          this.orderForm.sendContactPhone = sendData.contactPhone;
          this.orderForm.sendTelephone = sendData.telephone;
          this.orderForm.sendStreet = sendData.street;
          this.orderForm.sendAddressSelect = [sendData.provinceId, sendData.cityId, sendData.countyId];
          this.sendAddressSelectModel = [sendData.provinceId, sendData.cityId, sendData.countyId];
        }
      }
      this.sendAddressSelectChange();
    },
    searchItemNames () {
      getItemNames({
        token: this.token,
        filters: '',
        sorts: '',
        size: '50',
        page: '1'
      }).then((res) => {
        this.cargoNames = res.data.detailModelList;
      });
    },
    cargoNameChange (val) {
      let cargoName = null;
      let cargoNames = this.cargoNames;
      for (let i = 0; i < cargoNames.length; i++) {
        if (cargoNames[i].id === val.id) {
          cargoName = cargoNames[i];
        }
      }
      this.orderCargoForm.cargoTypeName = cargoName.typeModel.cnDictValname;
      this.orderCargoForm.cargoType = cargoName.type;
      this.orderCargoForm.cargoId = val.id;
      this.orderCargoForm.cargoName = val.name;
    },
    packTypeChanges (val) {
      let packTypeName = null;
      let packTypes = this.packTypes;
      for (let i = 0; i < packTypes.length; i++) {
        if (packTypes[i].dictVal === val) {
          packTypeName = packTypes[i];
        }
      }
      if (!isEmpty(packTypeName)) {
        this.orderCargoForm.packTypeName = packTypeName.cnDictValname;
      }
    },
    searchPackTypes () {
      getDictEntityByDictCode({token: this.token, dictCode: 109001}).then((res) => {
        this.packTypes = res.data.detailModelList;
      });
    },
    searchInvoiceTypes () {
      let filters = 'dictVal=101002005,101002006,101002007';
      getDictEntity({token: this.token, filters: filters}).then((res) => {
        this.invoiceTypes = res.data.detailModelList;
      });
    },
    searchReceiptTypes (val) {
      let filters = 'dictVal=101002003,101002004';
      getDictEntity({token: this.token, filters: filters}).then((res) => {
        this.receiptTypes = res.data.detailModelList;
      });
    },
    sendAddressSelectChange (val) {
      let shipmentAddressesSelectModel = this.shipmentAddressesSelectModel;
      let sendAddressSelectModel = this.sendAddressSelectModel;
      let shipmentAddressesModel = this.orderForm.shipmentAddressesSelect;
      let sendAddressModel = this.orderForm.sendAddressSelect;

      this.orderForm.shipmentsAddressId = this.shipmentAddressesSelectid;
      this.orderForm.sendAddressId = this.sendAddressSelectId;

      if (val === 'shipmentAddress' && (shipmentAddressesSelectModel[0] !== shipmentAddressesModel[0] || shipmentAddressesSelectModel[1] !== shipmentAddressesModel[1] || shipmentAddressesSelectModel[2] !== shipmentAddressesModel[2])) {
        this.orderForm.shipmentsAddressId = '';
      } else if (val === 'sendAddress' && (sendAddressSelectModel[0] !== sendAddressModel[0] || sendAddressSelectModel[1] !== sendAddressModel[1] || sendAddressSelectModel[2] !== sendAddressModel[2])) {
        this.orderForm.sendAddressId = '';
      }
      if (isEmpty(shipmentAddressesModel[2])) {
        return;
      }
      if (isEmpty(sendAddressModel[2])) {
        return;
      }
      this.shippings = [];
      searchLine({
        userId: this.orderForm.memberUserId,
        startOrderAddressId: this.orderForm.shipmentsAddressId,
        endOrderAddressId: this.orderForm.sendAddressId
      }).then((res) => {
        this.lineType = 0;
        this.orderForm.agingModel = '';
        if (res.data.successFlg) {
          let model = res.data;
          this.inds = false;
          this.hdds = false;
          /**
             * 合同快运
             */
          if (!isEmpty(model.obj) && model.obj.isFrhtContract === 111002001) {
            this.addValues[3].taxsheetTitleId = model.obj.taxsheetTitleId;
            this.addValues[3].value = model.obj.invoiceName;
            this.orderForm.valueMessage = model.obj.taxsheetTitleName;
            this.paymentTypes = [];
            if (!isEmpty(model.obj.receipt)) {
              this.hdds = true;
              this.addValues[2].dictValue = model.obj.receipt.toString();
              this.receiptType = model.obj.receipt.toString();
            }
            if (!isEmpty(model.obj.invoice)) {
              this.inds = true;
              let newInvoice = '101002005';
              if (model.obj.invoice === 102013001) {
                newInvoice = '101002005';
              }
              if (model.obj.invoice === 102013002) {
                newInvoice = '101002006';
              }
              if (model.obj.invoice === 102013003) {
                newInvoice = '101002007';
              }
              this.addValues[3].dictValue = newInvoice;
              this.invoiceTypeModel = newInvoice;
            }
            model.obj.ageingType = 112006004;
            model.obj.ageingTypeName = '合同快运';
            this.shippings = [model.obj];
            this.freightContract = res.data.obj;
            this.orderForm.agingDictEntityId = 112006004;
            this.lineType = 112006004;
            this.setContractAddValues(this.freightContract);
            this.paymentTypes = [{
              paymentType: model.obj.paymentType,
              paymentTypeName: model.obj.paymentTypeName
            }];
            this.orderForm.paymentType = model.obj.paymentType;
          } else {
            this.addvalues();
            this.searchTaxsheetTitle();
            this.lineType = 111002002;
            this.paymentTypes = [{
              paymentType: 102002001,
              paymentTypeName: '现付'
            }, {
              paymentType: 102002002,
              paymentTypeName: '到付'
            }, {
              paymentType: 102002006,
              paymentTypeName: '回单结'
            }];
            if (!isEmpty(model.detailModelList)) {
              this.shippings = model.detailModelList;
            }
            this.shippings.push({ageingType: 112006003, ageingTypeName: '定价快运'});
          }
        } else {
          this.shippings = [];
          this.$message.error('暂无该线路，请重新选择');
        }
      });
      this.orderForm.orderPrice = 0;
    },
    pricing () {
      this.orderPrices = [];
      if (!isEmpty(this.addValues[0].value)) { // 保价比例
        let bjv = this.addValues[0].value * this.figure(this.addValues[0].dictValue).value;
        getStmParamByType({
          stmParamType: 'INSURED_MINIMUM_INSURED'
        }).then((res) => {
          if (bjv < parseFloat(res.data.obj.stmParamVal)) {
            bjv = parseFloat(res.data.obj.stmParamVal);
          }
          this.orderPrices.push({
            costCode: 101002001,
            costName: '保价',
            costPrice: bjv
          });
        });
      }
      if (!isEmpty(this.addValues[1].value)) { // 代收货款比例
        this.orderPrices.push({
          costCode: 101002002,
          costName: '代收货款',
          costPrice: this.addValues[1].value * this.figure(this.addValues[1].dictValue).value
        });
      }

      let hdm = 0;
      let hdmv = 0;
      if (!isEmpty(this.addValues[2].value)) { // 回单比例
        hdm = this.addValues[2].value;
        hdmv = this.figure(this.addValues[2].dictValue).value;
      } else {
        hdm = 101002003;
        hdmv = this.figure(hdm).value;
      }
      this.orderPrices.push({
        costCode: hdm,
        costName: '回单',
        costPrice: hdmv
      });

      if (!isEmpty(this.freightPrice)) {
        this.orderPrices.push({costCode: 101005002, costName: '干线运费', costPrice: this.freightPrice});
      }
      if (!isEmpty(this.freightMsgPrice)) {
        this.orderPrices.push({costCode: 101005014, costName: '信息服务费', costPrice: this.freightMsgPrice});
      }
      if (!isEmpty(this.addValues[3].value && this.orderForm.agingDictEntityId !== 112006003)) { // 发票比例
        let sum = 0;
        for (let op in this.orderPrices) {
          if (!isEmpty(this.orderPrices[op].costPrice)) {
            sum += this.orderPrices[op].costPrice;
          }
        }
        this.orderPrices.push({
          costCode: this.addValues[3].dictValue,
          costName: '发票',
          costPrice: sum * this.figure(this.addValues[3].dictValue).value
        });
      }
      let totalPrice = 0;
      for (let orderPrice in this.orderPrices) {
        if (!isEmpty(this.orderPrices[orderPrice].costPrice)) {
          totalPrice += parseFloat(this.orderPrices[orderPrice].costPrice);
        }
      }
      this.orderForm.orderPrice = totalPrice;
    },
    figure (dictValue) {
      let data = {};
      for (let avd in this.addValueData) {
        if (this.addValueData[avd].dictValue === parseInt(dictValue)) {
          data = this.addValueData[avd];
          break;
        }
      }
      return data;
    },
    /**
       * 设置合同运价费率
       * @param con
       */
    setContractAddValues (con) {
      let newAddValues = [];
      let supportRatio = con.supportRatio;
      if (isEmpty(supportRatio)) {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002001) {
            supportRatio = this.addValueData[oa].value;
            break;
          }
        }
      }
      newAddValues.push({dictValue: 101002001, value: supportRatio});
      let collectRatio = con.collectRatio;
      if (isEmpty(collectRatio)) {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002002) {
            collectRatio = this.addValueData[oa].value;
            break;
          }
        }
      }
      newAddValues.push({dictValue: 101002002, value: collectRatio});
      if (isEmpty(con.receipt)) {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002003) {
            newAddValues.push({dictValue: 101002003, value: this.addValueData[oa].value});
            continue;
          }
          /**
             * 原件回单
             */
          if (this.addValueData[oa].dictValue === 101002004) {
            newAddValues.push({dictValue: 101002004, value: this.addValueData[oa].value});
            continue;
          }
        }
      } else {
        newAddValues.push({dictValue: con.receiptValue, value: con.receiptValue});
      }
      /**
         * 设置发票费率
         */
      if (!isEmpty(con.invoice)) {
        let newInvoice = 101002005;
        if (con.invoice === 102013001) {
          newInvoice = 101002005;
        }
        if (con.invoice === 102013002) {
          newInvoice = 101002006;
        }
        if (con.invoice === 102013003) {
          newInvoice = 101002007;
        }
        newAddValues.push({dictValue: newInvoice, value: con.invoiceRatio});
      } else {
        for (let oa in this.addValueData) {
          if (this.addValueData[oa].dictValue === 101002005) {
            newAddValues.push({dictValue: 101002005, value: this.addValueData[oa].value});
            continue;
          }
          /**
             * 单位普通发票
             */
          if (this.addValueData[oa].dictValue === 101002006) {
            newAddValues.push({dictValue: 101002006, value: this.addValueData[oa].value});
            continue;
          }
          /**
             * 增值税发票
             */
          if (this.addValueData[oa].dictValue === 101002007) {
            newAddValues.push({dictValue: 101002007, value: this.addValueData[oa].value});
            continue;
          }
        }
      }
      //
      this.addValueData = [];
      this.addValueData = newAddValues;
    },
    addvalues () {
      getFreightAddValue(this.token).then((res) => {
        this.addValueData = res.data.detailModelList;
      });
    },
    resetOrderForm () {
      location.reload();
    }
  },
  mounted () {
    this.searchMemberUsers();
    this.searchReservationRuleFreights();
    this.addvalues();
    this.searchItemNames();
    this.searchReceiptTypes();
    this.searchInvoiceTypes();
    searchDictEntitys('109002').then((res) => {
      if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
        this.addresstype = res.data.detailModelList;
      }
    });
  },
  computed: {
    discountText: function () {
      let self = this;
      if (isEmpty(this.lineType) || this.lineType === 111002001) {
        return '';
      }
      if (this.orderForm.shipmentsDate) {
        self.discount = this.shipmentsDateValuePOS.discount[this.orderForm.shipmentsDate.getTime()];
        if (isEmpty(this.discount)) {
          self.discount = '';
          return '';
        }
        let doms = this.discount.split('0.');
        if (doms.length === 1) {
          self.discount = '';
          return '';
        }
        self.discount = '0.' + doms[1].substring(0, 2);
        return this.shipmentsDateValuePOS.discount[this.orderForm.shipmentsDate.getTime()];
      } else {
        return '';
      }
    }
  }

}
;
</script>
